package com.hongtech.modules.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.hongtech.common.service.impl.CrudServiceImpl;
import com.hongtech.common.util.BeanCopierUtils;
import com.hongtech.modules.system.mapper.RegionMapper;
import com.hongtech.modules.system.dto.RegionDTO;
import com.hongtech.modules.system.entity.RegionEntity;
import com.hongtech.modules.system.service.RegionService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 地区
 *
 * @author lch 123456789@qq.com
 * @since 1.0.0 2023-09-16
 */
@Service
public class RegionServiceImpl extends CrudServiceImpl<RegionMapper, RegionEntity, RegionDTO> implements RegionService {

    @Override
    public List<RegionDTO> provinceList() {
        LambdaQueryWrapper<RegionEntity> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(RegionEntity::getLevel, 1);
        queryWrapper.orderByAsc(RegionEntity::getId);
        List<RegionEntity> list = baseDao.selectList(queryWrapper);
        return BeanCopierUtils.copyPropertiesList(list, RegionDTO.class);
    }

    @Override
    public List<RegionDTO> cityListByProvinceId(String provinceId) {
        LambdaQueryWrapper<RegionEntity> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(RegionEntity::getParentId, provinceId);
        queryWrapper.eq(RegionEntity::getLevel, 2);
        queryWrapper.orderByAsc(RegionEntity::getId);
        List<RegionEntity> list = baseDao.selectList(queryWrapper);
        return BeanCopierUtils.copyPropertiesList(list, RegionDTO.class);
    }

}
